import React from 'react';
import { AppstoreOutlined, CalculatorOutlined, DollarOutlined, CodeOutlined, ScheduleOutlined } from '@ant-design/icons';
import Huiben from './stock/huiben';
import Chengben from './stock/chengben';
import CurrencyConverter from './financial/currencyConverte';
import CodeEditor from './dev_tools/code-editor';
import CodeManagement from './dev_tools/code-management';
import CodeList from './dev_tools/code-list';
import Workflow from './dev_tools/workflow';
import WorkFlowList from './dev_tools/workflow-list';
import ScheduleList from './pages/schedule/list';
import NewSchedule from './pages/schedule/new'; // 假设你有这个组件，如果没有需要创建
import ScheduleDetail from './pages/schedule/detail'; // Import the detail component

export interface RouteItem {
  key: string;
  path: string;
  label: string;
  icon?: React.ReactNode;
  element: React.ReactNode;
  children?: RouteItem[];
}

export const routes: RouteItem[] = [
  {
    key: 'financial',
    path: '/financial',
    label: '金融工具',
    icon: <DollarOutlined />,
    element: null,
    children: [
      { key: 'huiben', path: '/stock/huiben', label: '股票回本计算器', element: <Huiben /> },
      { key: 'chengben', path: '/stock/chengben', label: '股票成本计算', element: <Chengben /> },
      { key: 'currency', path: '/financial/currencyConverte', label: '汇率转换器', element: <CurrencyConverter /> },
      // 其他金融工具路由...
    ]
  },
  {
    key: 'dev',
    path: '/dev_tools',
    label: '开发工具',
    icon: <CodeOutlined />,
    element: null,
    children: [
      { key: 'code-editor', path: '/dev_tools/code-editor', label: '代码编辑器', element: <CodeEditor initialContent="// 默认代码" /> },
      { key: 'code-list', path: '/dev_tools/code-list', label: '代码列表', element: <CodeList onSelect={() => {}} /> },
      { key: 'workflow', path: '/dev_tools/workflow', label: '流程设计器', element: <Workflow /> },
      { key: 'workflow-list', path: '/dev_tools/workflow-list', label: '流程列表', element: <WorkFlowList onSelect={() => {}} /> },
    ]
  },
  {
    key: 'schedule',
    path: '/schedule',
    label: '定时任务',
    icon: <ScheduleOutlined />,
    element: null,
    children: [
      { key: 'schedule-list', path: '/schedule/list', label: '定时任务列表', element: <ScheduleList /> },
      { key: 'schedule-new', path: '/schedule/new', label: '新建定时任务', element: <NewSchedule /> },
      { key: 'schedule-detail', path: '/schedule/:id', label: '任务详情', element: <ScheduleDetail /> },
    ]
  }
];

// 扁平化路由配置，用于 React Router
export const flattenRoutes = (routeItems: RouteItem[]): { path: string; element: React.ReactNode }[] => {
  return routeItems.reduce((acc, item) => {
    if (item.element) {
      acc.push({ path: item.path, element: item.element });
    }
    if (item.children) {
      acc.push(...flattenRoutes(item.children));
    }
    return acc;
  }, [] as { path: string; element: React.ReactNode }[]);
}; 